class Solution {
public:
    string convert(string s, int nRows) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function    
        if (nRows==1) return s;
        string ret="";
        for (int i=0;i<s.size();i+=2*nRows-2) ret+=s[i];
        for (int j=1;j<nRows-1;j++){
            for (int i=j;i<s.size();i+=2*nRows-2){
                ret+=s[i];
                if (i+2*(nRows-j-1)<s.size()) ret+=s[i+2*(nRows-j-1)];
            }
        }
        for (int i=nRows-1;i<s.size();i+=2*nRows-2) ret+=s[i];
        return ret;
    }
};
